import { Outlet, createHashRouter } from 'react-router-dom';
import { RootErrorBoundary, useRoutePerpare } from '@/utils';
import { Welcome } from './components';
import type { RouteObject } from 'react-router-dom';

console.log('版本号：', import.meta.env.SM_APP_VERSION);

const children: RouteObject[] = [
  {
    path: '',
    errorElement: <RootErrorBoundary />,
    lazy: async () => ({ Component: (await import('./pages/map')).MapPage }),
  },
];

const Perpare = () => {
  const { loading } = useRoutePerpare();
  return loading ? <Welcome /> : <Outlet />;
};

export const router = createHashRouter([
  {
    path: '/',
    lazy: async () => ({ Component: Perpare }),
    errorElement: <RootErrorBoundary />,
    children,
  },
  {
    path: '*',
    lazy: async () => ({ Component: (await import('@/utils')).NoMatch }),
  },
]);

if (import.meta.hot) {
  import.meta.hot.dispose(() => router.dispose());
}
